﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using ArtOfTest.WebAii.Silverlight.UI;
using ArtOfTest.WebAii.Controls.Xaml;
using Agility.Web.Resources;
using ArtOfTest.WebAii.Silverlight;
using Agility.Web.Models.DomainModel;
using ArtOfTest.Common.Exceptions;
using System.Globalization;

namespace Agility.TestProject.AppDriver
{
    public class AgilitySilverLightDriver : AppDriverBase
    {
        WebAii.WebAiiDriver slDriver;
        private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
        Guid ideaId;
        bool loggedIn;

        public AgilitySilverLightDriver()
        {
            logger.Debug("--> Entering ctor");
            this.loggedIn = false;
            this.slDriver = new WebAii.WebAiiDriver();
            logger.Debug("<-- Leaving ctor");
        }
        
        public override void Cleanup()
        {
            this.LogoutViaUI();
            this.slDriver.Cleanup();
            base.Cleanup();
        }

        public void StartBrowser()
        {
            slDriver.Initialize();
        }

        /// <summary>
        /// Verifies the user is the role passed in and logs the user on. Assigns the role to the user if not already assigned.
        /// </summary>
        /// <param name="role">the role to be verified</param>
        public void EnsureRoleAssignmentAndLogin(string role)
        {
            logger.Debug("--> Entering EnsureRoleAssignmentAndLogin");
            if (!this.IsInRole(role))
            {
                this.AssignRole(role);
                logger.Debug("Assigned role");
                logger.Trace("\t{0}", role);
            }
            logger.Debug("Verified user is in role");
            this.LoginViaUI(this.UserName);
            logger.Debug("Logged user in");
            logger.Trace("\tUser: {0}", this.UserName);
            logger.Debug("<-- Leaving EnsureRoleAssignmentAndLogin");
        }

        public void OpenRegistrationForm()
        {
            logger.Debug("--> Entering OpenRegistrationForm");
            FrameworkElement loginForm = this.OpenLoginRegistrationWindow();
            try
            {
                // Uncomment the following line to enable on screen annotations for WebAii actions
                //ArtOfTest.WebAii.Core.Manager.Current.Settings.AnnotateExecution = true;
                loginForm.Wait.ForVisible(1000);
                HyperlinkButton registerNow = loginForm.Find.ByName<HyperlinkButton>("registerNow");
                registerNow.Wait.ForNoMotion(100, 2000);
                registerNow.Refresh();
                registerNow.EnsureClickable();
                // Uncomment the following line to highlight (transparent red rectangle overlay) the UI element
                //registerNow.Highlight();
                logger.Trace("Actual Height: {0}", registerNow.ActualHeight.ToString());
                logger.Trace("Actual Width: {0}", registerNow.ActualWidth.ToString());
                logger.Trace("IsMouseOver: {0}", registerNow.IsMouseOver.ToString());
                logger.Trace("ScreenRectangle (Top/Left): {0}/{1}", registerNow.GetScreenRectangle().Top.ToString(), registerNow.GetScreenRectangle().Left.ToString());
                int x = (int)(registerNow.ActualWidth / 2);
                int y = (int)(registerNow.ActualHeight / 2);
                logger.Trace("ClickPoint (Top/Left): {0}/{1}", (registerNow.GetScreenRectangle().Top + y).ToString(), (registerNow.GetScreenRectangle().Left + x).ToString());
                registerNow.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftDoubleClick, new System.Drawing.Point(x, y));
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                // at least document it didn't
                logger.Error("Login Form was not displayed.");
            }
            catch (NullReferenceException)
            {
                logger.Error("Loginform is not displayed");//
            }
            catch (Exception e)
            {
                logger.Error(e.ToString());
                throw;
            }
            logger.Debug("<-- Leaving OpenRegistrationForm");
        }

        public string CompleteRegistrationForm()
        {
            logger.Debug("--> Entering CompleteRegistrationForm");
            string guidName = Guid.NewGuid().ToString();
            CompleteRegistrationForm(guidName, guidName);
            logger.Debug("<-- Leaving CompleteRegistrationForm");
            return guidName;
        }

        public void CompleteRegistrationForm(string userName, string email)
        {
            logger.Debug("--> Entering CompleteRegistrationForm");
            try
            {
                FrameworkElement registrationForm = slDriver.App.Find.ByName<FrameworkElement>("registrationForm");
                registrationForm.Wait.ForNoMotion(100, 3000);
                slDriver.App.FindName<TextBox>("textBoxUserName").Text = userName;
                slDriver.App.FindName<TextBox>("textBoxFriendlyName").Text = "Dave";
                slDriver.App.FindName<TextBox>("textBoxEmail").Text = string.Format(CultureInfo.InvariantCulture, "{0}@testing.com", email);
                slDriver.App.FindName<PasswordBox>("passwordBoxPassword").Password = "Test##100";
                slDriver.App.FindName<PasswordBox>("passwordBoxPasswordConfirmation").Password = "Test##100";
                slDriver.App.FindName<ComboBox>("comboBoxQuestion").SelectItemByIndex(false, 1);
                slDriver.App.FindName<TextBox>("textBoxAnswer").Text = "The Answer";
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Error("Registration form was not displayed");
            }
            logger.Debug("<-- Leaving CompleteRegistrationForm");
        }

        public void SubmitRegistration()
        {
            logger.Debug("--> Entering SubmitRegistration");
            try
            {
                // find the busyIndicators busyContent UI
                FrameworkElement registrationForm = slDriver.App.FindName("registrationForm");
                if (registrationForm.IsVisible)
                {
                    ContentPresenter busyContent = registrationForm.Find.ByName<ContentPresenter>("busycontent");
                    Button registerButton = registrationForm.Find.ByName<Button>("registerButton");
                    registerButton.EnsureClickable();
                    registerButton.User.Click();
                }
                else
                {
                    logger.Error("Registration form was not displayed");
                }
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            logger.Debug("<-- Leaving SubmitRegistration");
        }

        public bool VerifyLoginStatus()
        {
            logger.Debug("--> Entering VerifyLoginStatus");
            bool result = false;
            try
            {
                Button logoutButton = slDriver.App.Find.ByName<Button>("logoutButton");
                logoutButton.Wait.ForVisible(15000);
                result = logoutButton.IsEnabled;
                this.loggedIn = result;
                if (!result)
                {
                    logger.Info("Logout button is disabled");
                }
            }
            catch (TimeoutException)
            {
                logger.Error("RegistrationWindow did not close.");
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            logger.Debug("<-- Leaving VerifyLoginStatus: {0}", result == true ? "Passed" : "Failed");
            return result;
        }

        public bool VerifyDisplayName()
        {
            logger.Debug("--> Entering VerifyDisplayName");
            bool result = false;
            try
            {
                result = slDriver.App.FindName<TextBlock>("welcomeText").Text.EndsWith("Dave");
                if (!result)
                {
                    logger.Info("Wrong username displayed in the welcome message");
                }
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            logger.Debug("<-- Leaving VerifyDisplayName: {0}", result == true ? "Passed" : "Failed");
            return result;
        }

        private FrameworkElement OpenLoginRegistrationWindow()
        {
            logger.Debug("--> Entering OpenLoginRegistrationWindow");
            FrameworkElement loginForm = null;
            try
            {
                FrameworkElement expNavigation = slDriver.App.Find.ByName<FrameworkElement>("expNavigation");
                expNavigation.User.HoverOver();
                UserControl loginStatus = slDriver.App.Find.ByName<UserControl>("loginStatus");
                Button loginButton = loginStatus.Find.ByName<Button>("loginButton");
                loginButton.Wait.ForVisible();
                loginButton.EnsureClickable();
                loginButton.User.Click();
                loginForm = slDriver.App.Find.ByName<FrameworkElement>("loginForm");
            }
            catch (TimeoutException)
            {
                // at least document it didn't
                logger.Error("Login/Registration window did not open");
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            logger.Debug("<-- Leaving OpenLoginRegistrationWindow");
            return loginForm;
        }

        public void LoginViaUI(string userName)
        {
            logger.Debug("--> Entering LoginViaUI");
            FrameworkElement loginForm = this.OpenLoginRegistrationWindow();
            try
            {
                loginForm.Wait.ForNoMotion(100, 1000);
                TextBox userNameTextBox = loginForm.Find.ByName<TextBox>("textBoxLoginUserName");
                userNameTextBox.Refresh();
                userNameTextBox.EnsureClickable();
                userNameTextBox.User.TypeText(userName, 20);
                logger.Debug("Filled in the username");
                PasswordBox pwBox = loginForm.Find.ByName<PasswordBox>("passwordBoxLoginPassword");
                pwBox.Refresh();
                pwBox.EnsureClickable();
                pwBox.User.TypeText("Test##100", 20);
                logger.Debug("Filled in the password");
                // find the busyIndicators busyContent UI
                Button loginButton = loginForm.Find.ByName<Button>("loginButton");
                loginButton.EnsureClickable();
                loginButton.User.Click();
                // 15s timeout to ensure there's enough time to ramp up the services, attach the DB-file, etc.
                loginForm.Wait.ForVisibleNot(15000);
                logger.Debug("Submitted the login form");
                this.loggedIn = true;
            }
            catch (NullReferenceException)
            {
                logger.Error("loginForm not available.");
            }
            catch (ArtOfTest.Common.Exceptions.FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Error("Login form was not closed.");
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            logger.Debug("<-- Leaving LoginViaUI");
        }

        public void LogoutViaUI()
        {
            logger.Debug("--> Entering LogoutViaUI");
            try
            {
                UserControl loginStatus = slDriver.App.Find.ByName<UserControl>("loginStatus");
                Button logoutButton = loginStatus.Find.ByName<Button>("logoutButton");
                logoutButton.EnsureClickable();
                logoutButton.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftDoubleClick);
                logoutButton.Wait.ForVisibleNot(1000);
                this.loggedIn = false;
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Error("Logout button is still displayed");
            }
            logger.Debug("<-- Leaving LogoutViaUI");
        }

        public bool VerifyValidationErrorNotification(string property)
        {
            logger.Debug("--> Entering VerifyValidationErrorNotification for {0}", property);
            bool result = false;
            FrameworkElement registrationForm = null;
            try
            {
                registrationForm = slDriver.App.FindName("registrationForm");
                FrameworkElement field = null;
                switch (property)
                {
                    case "Username":
                        field = registrationForm.Find.ByName<TextBox>("textBoxUserName");
                        break;
                    case "Email":
                        field = registrationForm.Find.ByName<TextBox>("textBoxEmail");
                        break;
                    default:
                        break;
                }
                slDriver.App.Find.Strategy = FindStrategy.WhenNotVisibleReturnElementProxy;
                Border errorHelper = field.Find.ByName<Border>("ValidationErrorElement");
                errorHelper.Wait.ForVisible(10000);
                result = true;
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Info("No error notification shown for {0}", property);
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            finally
            {
                slDriver.App.Find.Strategy = FindStrategy.WhenNotVisibleThrowException;
                if (registrationForm != null)
                {
                    Button cancelButton = registrationForm.Find.ByName<Button>("registerCancel");
                    cancelButton.EnsureClickable();
                    cancelButton.User.Click();
                    logger.Debug("Canceled the registration form");
                }
            }
            logger.Debug("<-- Leaving VerifyValidationErrorNotification: {0}", result == true ? "Passed" : "Failed");
            return result;
        }

        public bool VerifyAllMyIdeasDisplayed()
        {
            logger.Debug("--> Entering VerifyAllMyIdeasDisplayed");
            try
            {
                this.WaitForMyIdeasDisplayed();
                DataGrid dataGridMyIdeas = slDriver.App.FindName<DataGrid>("dataGridMyIdeas");
                dataGridMyIdeas.Refresh();
                if (dataGridMyIdeas.RowElements.Count != this.TestEpics.Where(e => e.RequestedBy == this.UserName).Count())
                {
                    logger.Debug("Wrong number of epics displayed");
                    logger.Trace("Expected: {0}, Actual: {1}", this.TestEpics.Where(e => e.RequestedBy == this.UserName).Count(), dataGridMyIdeas.RowElements.Count);
                    logger.Debug("<-- Leaving VerifyAllMyIdeasDisplayed");
                    return false;
                }
                DateTime referenceDate = DateTime.MinValue;
                string referenceText = string.Empty;
                foreach (DataGridRow row in dataGridMyIdeas.RowElements)
                {
                    if (row.CellElements.SingleOrDefault(c => c.CellText == this.UserName) == null)
                    {
                        logger.Debug("Epic of different user displayed");
                        logger.Trace("Logged in user: {0}, requester of epic: {1}", this.UserName, row.CellElements.ElementAt(3).CellText);
                        logger.Debug("<-- Leaving VerifyAllMyIdeasDisplayed");
                        return false;
                    }
                    if (DateTime.Parse(row.CellElements.ElementAt(0).CellText) < referenceDate)
                    {
                        logger.Debug("Epics not sorted by date");
                        logger.Trace("previous row date: {0}, current row date: {1}", referenceDate.ToString(), row.CellElements.ElementAt(0).CellText);
                        logger.Debug("<-- Leaving VerifyAllMyIdeasDisplayed");
                        return false;
                    }
                    else if (DateTime.Parse(row.CellElements.ElementAt(0).CellText) == referenceDate)
                    {
                        if (string.Compare(referenceText, row.CellElements.ElementAt(1).CellText, StringComparison.InvariantCulture) > 0)
                        {
                            logger.Debug("Epics not sorted by title");
                            logger.Trace("previous row title: {0}, current row title: {1}", referenceText, row.CellElements.ElementAt(1).CellText);
                            logger.Debug("<-- Leaving VerifyAllMyIdeasDisplayed");
                            return false;
                        }
                    }
                    referenceDate = DateTime.Parse(row.CellElements.ElementAt(0).CellText);
                    referenceText = row.CellElements.ElementAt(1).CellText;
                }
                logger.Debug("All Epics displayed as expected");
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            logger.Debug("<-- Leaving VerifyAllMyIdeasDisplayed");
            return true;
        }

        public bool VerifyAllMyIdeasDetailsDisplayed()
        {
            logger.Debug("--> Entering VerifyAllmyIdeasDetailsDisplayed");
            bool result = true;
            try
            {
                DataGrid dataGridMyIdeas = slDriver.App.FindName<DataGrid>("dataGridMyIdeas");
                dataGridMyIdeas.Refresh();
                IList<IDataGridColumnHeader> headerRow = dataGridMyIdeas.ColumnHeaderElements;
                if (headerRow.Count != 5)
                    result = false;
                if (headerRow.SingleOrDefault(c => c.Text.Equals(EpicResources.EpicCreationDate)) == null)
                    result = false;
                if (headerRow.SingleOrDefault(c => c.Text.Equals(EpicResources.EpicTitle)) == null)
                    result = false;
                if (headerRow.SingleOrDefault(c => c.Text.Equals(EpicResources.EpicDescription)) == null)
                    result = false;
                if (headerRow.SingleOrDefault(c => c.Text.Equals(EpicResources.EpicRequestedBy)) == null)
                    result = false;
                // TODO: Add verification of approval status
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
                result = false;
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                result = false;
                throw;
            }
            logger.Debug("<-- Leaving VerifyAllmyIdeasDetailsDisplayed");
            return result;
        }

        private void WaitForMyIdeasDisplayed()
        {
            logger.Debug("--> Entering WaitForMyIdeasDisplayed");
            try
            {
                slDriver.App.Find.Strategy = FindStrategy.WhenNotVisibleReturnElementProxy;
                UserControl myIdeas = slDriver.App.Find.ByName<UserControl>("controlMyIdeas");
                myIdeas.Wait.ForVisible(3000);
                logger.Debug("MyIdeas control is displayed");
            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Error("myIdeas control was not displayed.");
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            finally
            {
                slDriver.App.Find.Strategy = FindStrategy.WhenNotVisibleThrowException;
            }
            logger.Debug("<-- Leaving WaitForMyIdeasDisplayed");
        }

        public void AddNewIdea()
        {
            logger.Debug("--> Entering AddNewIdea");
            string title = "My New Idea";
            string description = "This is the description of my new idea";
            this.ideaId = Guid.NewGuid();
            this.TestEpics.Add(Epic.CreateEpic(this.ideaId, title, description, DateTime.Today, this.UserName));
            this.WaitForMyIdeasDisplayed();
            try
            {
                FrameworkElement dataformIdea = slDriver.App.FindName("dataFormIdea");
                dataformIdea.Wait.ForVisible(1000);
                dataformIdea.Refresh();
                FrameworkElement addnewButton = dataformIdea.Find.ByName("NewItemButton");
                addnewButton.EnsureClickable();
                addnewButton.User.Click();

            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Error("Dataform for idea details is not displayed");
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            logger.Debug("<-- Leaving AddNewIdea");
        }

        public void EnterIdeaDetails()
        {
            logger.Debug("--> Entering EnterIdeaDetails");
            try
            {
                FrameworkElement dataformIdea = slDriver.App.FindName("dataFormIdea");
                dataformIdea.Wait.ForVisible(1000);
                dataformIdea.Refresh();
                dataformIdea.Find.ByName<TextBox>("textBoxTitle").Text = this.TestEpics.Single(e => e.Id == this.ideaId).Title;
                logger.Debug("Updated the title via the UI");
                dataformIdea.Find.ByName<TextBox>("textBoxDescription").Text = this.TestEpics.Single(e => e.Id == this.ideaId).Description;
                logger.Debug("Updated the description via the UI");

            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Error("Textboxes for idea title and description are not displayed");
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            }
            logger.Debug("<-- Leaving EnterIdeaDetails");
        }

        public void ConfirmIdea()
        {
            logger.Debug("--> Entering ConfirmIdea");
            try
            {
                FrameworkElement dataformIdea = slDriver.App.FindName("dataFormIdea");
                Button commitButton = dataformIdea.Find.ByName<Button>("CommitButton");
                commitButton.EnsureClickable();
                commitButton.User.Click();
                logger.Debug("Clicked on the CommitButton");

            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            } logger.Debug("<-- Leaving ConfirmIdea");
        }

        public void SelectIdeaFromGrid()
        {
            logger.Debug("--> Entering SelectIdeaFromGrid");
            try
            {
                WaitForMyIdeasDisplayed();
                DataGrid myIdeasGrid = slDriver.App.FindName<DataGrid>("dataGridMyIdeas");
                myIdeasGrid.Refresh();
                myIdeasGrid.EnsureClickable();
                myIdeasGrid.RowElements[1].User.Click();
                logger.Debug("Selected Idea in row [1]");
                int titleIndex = myIdeasGrid.ColumnHeaderElements.IndexOf(myIdeasGrid.ColumnHeaderElements.Single(c => c.Text == EpicResources.EpicTitle));
                string title = myIdeasGrid.RowElements[1].CellElements[titleIndex].Text;
                this.ideaId = this.TestEpics.Single(e => e.Title == title).Id;
                logger.Trace("with Id: {0}", this.ideaId.ToString());
                FrameworkElement dataform = slDriver.App.FindName("dataFormIdea");
                dataform.Find.ByName<TextBox>("textBoxTitle").Wait.ForVisible(1000);

            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (TimeoutException)
            {
                logger.Error("Idea details are not displayed");
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            } 
            logger.Debug("<-- Leaving SelectIdeaFromGrid");
        }

        public void UpdateIdeaDetails()
        {
            logger.Debug("--> Entering UpdateIdeaDetails");
            try
            {
                this.TestEpics.Single(e => e.Id == this.ideaId).Title = "Updated Title";
                logger.Debug("Changed title of {0} idea in list", this.ideaId.ToString());
                logger.Trace("New Title: {0}", this.TestEpics.Single(e => e.Id == this.ideaId).Title);
                this.TestEpics.Single(e => e.Id == this.ideaId).Description = "Updated Description";
                logger.Debug("Changed description of {0} idea in list", this.ideaId.ToString());
                logger.Trace("New Description: {0}", this.TestEpics.Single(e => e.Id == this.ideaId).Description);
                FrameworkElement dataForm = slDriver.App.FindName("dataFormIdea");
                Button editButton = dataForm.Find.ByName<Button>("EditButton");
                editButton.EnsureClickable();
                editButton.User.Click();

            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            } 
            logger.Debug("<-- Leaving UpdateIdeaDetails");
        }

        public bool VerifyUpdatedDetailsDisplayed()
        {
            logger.Debug("--> Entering VerifyUpdatedDetailsDisplayed");
            try
            {
                DataGrid myIdeasGrid = slDriver.App.FindName<DataGrid>("dataGridMyIdeas");
                myIdeasGrid.Refresh();
                int titleIndex = myIdeasGrid.ColumnHeaderElements.IndexOf(myIdeasGrid.ColumnHeaderElements.Single(c => c.Text == EpicResources.EpicTitle));
                int descriptionIndex = myIdeasGrid.ColumnHeaderElements.IndexOf(myIdeasGrid.ColumnHeaderElements.Single(c => c.Text == EpicResources.EpicDescription));
                IDataGridRow dataRow = myIdeasGrid.RowElements[1];
                if (dataRow.CellElements[titleIndex].Text != this.TestEpics.Single(e => e.Id == this.ideaId).Title)
                {
                    logger.Debug("Title for epic {0} not ok. Expected: {1}, Actual {2}", this.ideaId.ToString(), this.TestEpics.Single(e => e.Id == this.ideaId).Title, dataRow.CellElements[titleIndex].Text);
                    logger.Debug("<-- Leaving VerifyUpdatedDetailsDisplayed");
                    return false;
                }
                logger.Debug("Title ok");
                if (dataRow.CellElements[descriptionIndex].Text != this.TestEpics.Single(e => e.Id == this.ideaId).Description)
                {
                    logger.Debug("Description for epic {0} not ok. Expected: {1}, Actual {2}", this.ideaId.ToString(), this.TestEpics.Single(e => e.Id == this.ideaId).Description, dataRow.CellElements[descriptionIndex].Text);
                    logger.Debug("<-- Leaving VerifyUpdatedDetailsDisplayed");
                    return false;
                }
                logger.Debug("Description ok");

            }
            catch (FindElementException e)
            {
                logger.Error(e.Message);
            }
            catch (Exception e)
            {
                logger.Fatal(e.ToString());
                throw;
            } 
            logger.Debug("<-- Leaving VerifyUpdatedDetailsDisplayed");
            return true;
        }
    }
}
